<?
//các file upload ???c ?? trong 1 th? m?c riêng
require("path/file_path_download.php");
include("admin/connect.php");
$matl=$_GET["matl"];
//$d_count=$_GET{"d_count"};
//lay tên file can download tu URL
$filename = isset($_GET['file'])?$_GET['file']:'';
 
//thuc hien quá trình kiem tra
if ( !preg_match('/^[a-z0-9\_\-][a-z0-9\_\-\. ]*$/i', $filename) || !is_file($upload_dir.$filename) || !is_readable($upload_dir.$filename) ) 
	{	        
		exit(-1);
	} 
 $sql="update tailieu set solandown=solandown + 1 where matl='{$matl}'";
 mysql_query($sql,$link);

//m? file ?? ??c v?i ch? ?? nh? phân (binary)
$fp = fopen($upload_dir.$filename, "rb");
 
//gui header ??n cho browser
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$filename.'"');
header('Content-length: ' . filesize($upload_dir.$filename)); 

//??c file và tr? d? li?u v? cho browser
fpassthru($fp);
fclose($fp);
?>
